package com.oocl.myProject;

public class MySort {
	public void selectSort(int[] a){
		for (int i = 0; i < a.length-1; i++) {
//			int min = a[i];
			for (int j = i+1; j < a.length; j++) {
				if(a[i]>a[j]){
					int temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}	
		}
		
	}
	
	public void bubbleSort(int[] a){
		for (int i = 0; i < a.length-1; i++) {
			for (int j = 0; j < a.length-i-1; j++) {
				if (a[j]>a[j+1]) {
					int temp = a[j];
					a[j]=a[j+1];
					a[j+1]=temp;	
				}
				
			}
			
		}	
	}
	
	public int binarySearch(int[] srcArray, int des){    
	    int low = 0;   
	    int high = srcArray.length-1;   
	    while(low <= high) {   
	        int middle = (low + high)/2;   
	        if(des == srcArray[middle]) {   
	            return middle;   
	        }else if(des <srcArray[middle]) {   
	            high = middle - 1;   
	        }else {   
	            low = middle + 1;   
	        }  
	    }  
	    return -1;  
    }

}
